package cn.faster.sys.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import java.util.*;
import cn.faster.common.result.ResultBean;
import cn.faster.sys.service.SysUserRoleCenterService;
import cn.faster.sys.entity.SysUserRoleCenter;

/**
 * <p>
 * 用户角色中间表 前端控制器
 * </p>
 *
 * @author xiaoCoder
 * @date 2021-06-10
 */
@RestController
@CrossOrigin
@AllArgsConstructor
@Api(value = "用户角色中间表",tags = "用户角色中间表")
@RequestMapping("/sys/userRoleCenter")
public class SysUserRoleCenterController {

    private final SysUserRoleCenterService sysUserRoleCenterService;

    @ApiOperation(value = "获取userRoleCenter根据id",notes="")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer")
    @GetMapping("/getById")
    public ResultBean userRoleCenter(@RequestParam(value = "id") Integer id) throws Exception {

        SysUserRoleCenter sysUserRoleCenter = sysUserRoleCenterService.getUserRoleCenterById(id);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(sysUserRoleCenter);
        return resultBean;
    }

    @ApiOperation(value = "获取userRoleCenter列表",notes="")
    @ApiImplicitParam(name = "map", value = "userRoleCenter实体中的参数", dataType ="Map")
    @GetMapping("")
    public ResultBean userRoleCenterList(@RequestParam(required = false) Map<String, Object> map) throws Exception {

        List<SysUserRoleCenter> sysUserRoleCenterList = sysUserRoleCenterService.listUserRoleCenter(map);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(sysUserRoleCenterList);
        return resultBean;
    }


    @ApiOperation(value = "添加userRoleCenter",notes="新增一条userRoleCenter")
    @ApiImplicitParam(name = "userRoleCenter", value = "userRoleCenter实体中的参数", required = true, dataType = "UserRoleCenter")
    @PostMapping("")
    public ResultBean userRoleCenterAdd(@RequestBody SysUserRoleCenter sysUserRoleCenter) throws Exception {

        Integer flag = sysUserRoleCenterService.addUserRoleCenter(sysUserRoleCenter);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(flag);
        return resultBean;
    }

    @ApiOperation(value = "修改userRoleCenter",notes="根据id修改user_role_center")
    @ApiImplicitParam(name = "userRoleCenter", value = "userRoleCenter实体", required = true, dataType = "UserRoleCenter")
    @PutMapping("")
    public ResultBean userRoleCenterUpdate(@RequestBody SysUserRoleCenter sysUserRoleCenter) throws Exception {

        Integer flag = sysUserRoleCenterService.updateUserRoleCenter(sysUserRoleCenter);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(flag);
        return resultBean;
    }
    @ApiOperation(value = "物理删除userRoleCenter",notes="根据id物理删除userRoleCenter")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer")
    @DeleteMapping("/{id}")
    public ResultBean userRoleCenterDelete(@PathVariable(name = "id") Integer id) throws Exception {

        Integer flag = sysUserRoleCenterService.deleteUserRoleCenterById(id);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(flag);
        return resultBean;
    }

    @ApiOperation(value = "逻辑删除userRoleCenter",notes="根据id逻辑删除userRoleCenter")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer")
    @PostMapping("/removeById")
    public ResultBean userRoleCenterRemove(@RequestParam(value = "id") Integer id) throws Exception {

        Integer flag = sysUserRoleCenterService.removeUserRoleCenterById(id);
        ResultBean resultBean = new ResultBean();
        resultBean.fillData(flag);
        return resultBean;
    }
}
